#pragma once

#include <math.h>

namespace VIS
{
	class CSphereCamera
	{
	public:
		CSphereCamera(void);
		~CSphereCamera(void);

		void centerOn(float _lon, float _lat);
		void getTransformMatrix();
		void rotateGlobe(int _dx, int _dy);
		void rotateLocal(int _dx, int _dy);
		void getMatrixMouseRefer();

		void zoomGlobe(bool _dir);
	 
		//static
		static double vlen(double _x, double _y, double _z) { return sqrt(_x*_x + _y*_y + _z*_z);}
		template<typename T>
		static void invertMatrix(const T *m, T *out );
		static void global2localCoords(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, double *invModelView);
		
		float get3DCoords(double _sx, double _sy, double &_3dx, double &_3dy, double &_3dz);
		float getCur3DCoords(double &_3dx, double &_3dy, double &_3dz); 

		void setMousePos(int _x, int _y){ m_mouseX = _x; m_mouseY = _y;}

		void setupViewPort(int _width, int _height);

		float  m_projection[16];
		float  m_modelView[16];
		int    m_viewPort[4];
		double md_modelView[16];
		double md_projection[16];
		double md_invModelView[16];
		double m_modelViewScale;

	private:
		double m_left;
		double m_right;
		double m_bottom;
		double m_top;
		double m_near;
		double m_far;
		double m_size;
		double m_modelViewRefer[16];
		double m_invModelViewRefer[16];
		double m_horizontalAxis[3];
		double m_verticalAxis[3];
		double m_referLoc3Dx;
		double m_referLoc3Dy;
		double m_referLoc3Dz;

		float m_referLocDepth;
		int m_mouseX;
		int m_mouseY;
		


	};
}
